
<!DOCTYPE html>
<html>
<head>
    <title>Android无障碍节点查看器</title>
    <meta charset="utf-8">
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f7fa;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 30px;
        }
        .controls {
            display: flex;
            gap: 15px;
            margin-bottom: 30px;
            justify-content: center;
        }
        .refresh-btn {
            padding: 10px 20px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .refresh-btn:hover {
            background-color: #2980b9;
        }
        .search-box {
            padding: 10px 15px;
            width: 300px;
            border: 2px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
            transition: border-color 0.3s;
        }
        .search-box:focus {
            border-color: #3498db;
            outline: none;
        }
        .node {
            background: white;
            margin: 10px 0;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            transition: transform 0.2s, box-shadow 0.2s;
        }
        .node:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.15);
        }
        .node-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 10px;
        }
        .node-item {
            padding: 5px;
            color: #34495e;
        }
        .node-item span {
            font-weight: bold;
            color: #7f8c8d;
        }
        .children {
            margin-left: 25px;
            padding-left: 15px;
            border-left: 2px solid #e0e0e0;
        }
    </style>
    <script>
        function refreshNodes() {
            fetch('/nodes')
                .then(response => response.json())
                .then(data => {
                    document.getElementById('nodes-container').innerHTML = 
                        renderNode(data);
                });
        }

        function filterNodes() {
            const searchText = document.getElementById('search-input').value.toLowerCase();
            const nodes = document.getElementsByClassName('node');
            for (let node of nodes) {
                const text = node.innerText.toLowerCase();
                if (text.includes(searchText)) {
                    node.style.display = 'block';
                    node.style.opacity = '1';
                } else {
                    node.style.display = 'none';
                    node.style.opacity = '0.5';
                }
            }
        }

        function renderNode(node) {
            let html = '<div class="node">';
            html += '<div class="node-content">';

            if (node.text || node.content_desc) {
                html += `
                    <div class="node-item"><span>文本:</span> ${node.text || '无'}</div>
                    <div class="node-item"><span>资源ID:</span> ${node['resource-id'] || '无'}</div>
                    <div class="node-item"><span>类名:</span> ${node.class || '无'}</div>
                    <div class="node-item"><span>描述:</span> ${node['content-desc'] || '无'}</div>
                    <div class="node-item"><span>位置:</span> ${node.bounds || '无'}</div>
                `;
            }

            html += '</div>';

            if (node.children) {
                html += '<div class="children">';
                for (let child of node.children) {
                    html += renderNode(child);
                }
                html += '</div>';
            }

            html += '</div>';
            return html;
        }

        // 页面加载完成后自动刷新一次
        document.addEventListener('DOMContentLoaded', refreshNodes);

        // 自动刷新
        setInterval(refreshNodes, 2000);
    </script>
</head>
<body>
    <div class="container">
        <h1>Android无障碍节点查看器</h1>
        <div class="controls">
            <button class="refresh-btn" onclick="refreshNodes()">手动刷新</button>
            <input type="text" id="search-input" class="search-box" 
                   onkeyup="filterNodes()" placeholder="搜索节点...">
        </div>
        <div id="nodes-container"></div>
    </div>
</body>
</html>
    